import React from 'react'
import classNames from 'classnames'
import {withRouter} from 'react-router'
import './style.scss'
import Button from "../button/index";
import './style.scss'

const FuncButton =(props)=>{
  let defaultProps = {showLeft: true, showRight: true}
  const{wrapperName,leftTo,rightTo,leftText,rightText,children, showRight, showLeft} = Object.assign({}, defaultProps, props);
  return(
    <div className={classNames('button-wrapper',wrapperName)}>
      {showLeft && <Button className={'button-left'} onClick={()=>{
        if(typeof leftTo ==='string'||typeof leftTo === 'object'){
          props.router.push(leftTo)
        }
        else if(typeof leftTo ==='function'){
          leftTo();
        }
      }}>{leftText}</Button>}
      {showRight && <Button className={'button-right'} onClick={()=>{
        if(typeof rightTo ==='string'||typeof rightTo === 'object'){
          props.router.push(rightTo)
        }
        else if(typeof rightTo ==='function'){
          rightTo();
        }
      }}>{rightText}</Button>}
      {children}
    </div>
  )
};

export default withRouter(FuncButton);
